<%= render 'base' %>

<div class="subnav">
  <nav class="subnav-links">
    <a href="<%= comments_path %>" class="subnav-item"><%= t("admin.All") %></a>
  </nav>
  <div class="subnav-search float-left">
    <form action="" method="GET">
      <input type="search" name="q" class="form-control subnav-search-input" value="<%= params[:q] %>">
      <%= icon_tag "search", class: "subnav-search-icon" %>
    </form>
  </div>
</div>

<div class="admin-admin_comments comments">
  <table class="table table-striped">
    <tr class="head">
      <td></td>
    </tr>
    <% @comments.each do |item| %>
    <%
    can_read = can?(:read, item.commentable)
    %>
    <tr id="comment-<%= item.id %>" class="comment <%= " hide-comment" unless can_read %>">
      <td>
        <div class="mb-2"><%= link_to item.commentable_title, item.to_url, class: "link-gray" %></div>
        <div class="markdown-body my-4">
          <% if can_read %>
            <%= item.body_plain %>
          <% else %>
            <p class="text-gray"><%= t(".Private contents, hide comment") %></span>
          <% end %>
        </div>
        <div class="info text-gray clearfix">
          <span class="mr-2">#<%= item.id %></span>
          <%= user_avatar_tag(item.user, style: :tiny) %> <%= user_name_tag(item.user) %> <%= t("created at") %> <%= timeago(item.created_at) %>

          <div class="opts float-right">
            <% if can_read %>
              <%= link_to icon_tag("pencil"), edit_admin_comment_path(item.id), class: "btn-edit" %>
              <%= link_to icon_tag("trash"), admin_comment_path(item.id), method: :delete, remote: true, 'data-confirm' => t("admin.Are you sure delete this item?") %>
            <% end %>
          </div>
        </div>
      </td>
    </tr>
    <% end %>
  </table>
  <%= paginate @comments %>
</div>
